package cn.lili;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

@SpringBootApplication
@EnableFeignClients
@Slf4j
public class PaymentApplication implements ApplicationRunner {

    public static void main(String[] args) {
        //1
        System.setProperty("nacos.logging.default.config.enabled","false");
        SpringApplication.run(PaymentApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        try {
            // 1. 打开文件
            FileInputStream fileInputStream = new FileInputStream("/app/config-file-secret/yl_apiclient_key.pem");
            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

            // 2. 读取文件内容
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                // 处理每一行内容，这里简单打印到控制台
                System.out.println(line);
            }

            // 3. 关闭资源
            bufferedReader.close();
            inputStreamReader.close();
            fileInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
            log.error("未读取到配置");
        }
    }
}
